const
  NMAX = 50;
  WMAX = 1000;
  INF = 1000000;

var
  n, d, i, j: longint;
  w: array[1 .. NMAX] of longint;
  f: array[0 .. NMAX * WMAX + WMAX, 1 .. NMAX] of longint;
  fullWeight: longint;

begin
  read(n);
  fullWeight := 0;
  for i := 1 to n do
  begin
    read(w[i]);
    fullWeight := fullWeight + w[i];
  end;

  for i := 0 to fullWeight + WMAX do
    for j := 1 to n do
      f[i][j] := INF;
  f[0][1] := w[1];
  f[w[1]][1] := 0;

  for j := 2 to n do
  begin
    for i := 0 to fullWeight do
    begin
      // пробуем слиток отдать
      if f[i][j - 1] + w[j] < f[i][j] then
        f[i][j] := f[i][j - 1] + w[j];
      // пробуем слиток не отдавать
      d := abs(i - w[j]);
      if f[i][j - 1] < f[d][j] then
        f[d][j] := f[i][j - 1];
      // пробуем слиток не отдавать, но поместить в другую кучу
      d := abs(i + w[j]);
      if f[i][j - 1] < f[d][j] then
        f[d][j] := f[i][j - 1];
    end;
  end;
  writeln(f[0][n]);
end.
